import { createStore, StoreOptions,Commit } from 'vuex';
import DocStore from './modules/doc/doc';

const TEST_TYPE = 'TEST_TYPE';

const storeConfig: StoreOptions<RootState> = {
  state: {
    zpa: 'ddd',
    name: 'storeName',
  },
  mutations: {
    [TEST_TYPE](state) {
      state.name = (+new Date()).toString();
    },
  },
  getters: {
    posts: (state) => state,
  },
  actions: {
    fetchPosts({ commit}:{commit:Commit}) {
      console.log(213213);
      commit(TEST_TYPE);
    },
    show({ commit,dispatch }) {
      dispatch("ddd");
      commit(TEST_TYPE);
    },
  },
  modules: {
    DocStore,
  },
}; 


// // 提取 mutation 函数类型
// type CommitFuncs = (
//   typeof storeConfig.mutations
// )
// // 将 mutation 函数名及 payload 类型转换成 commit 函数的两个入参类型
// interface Commit{
//   <T extends keyof CommitFuncs>(type: T, payload?: Parameters<CommitFuncs[T]>[1]): void;
// }

// type mType =  typeof storeConfig.mutations; 
// let cc = {
//   getInfo<T extends keyof {"ddd":1,"cccc":2}>(type: T):void{}
  
// }

// cc.getInfo("dd");
 

// type DispatchFuncs = (
//   typeof storeConfig.actions
// )

// // 将 getter 函数转换成 {getterName: getterFuncsReturnType} 的对象类型
// type ReturnGetters<T extends { [key: string]: (...args: any) => any }> = {
//   [P in keyof T]: ReturnType<T[P]>;
// }

// interface Dispatch {
//   <T extends keyof DispatchFuncs>(type: T, payload?: Parameters<DispatchFuncs[T]>[1]): Promise<any>;
// }


//type Getters = ReturnGetters<typeof moduleGetters>;
 
 
const store = createStore(storeConfig);


export default store;
